Given an integer, determine if it is a Palindrome in less than O(n) [on hold]
Posted
by
user134235
on Programmers
See other posts from Programmers
or by user134235
Published on 2014-06-02T05:52:58Z
Indexed on
2014/06/02
15:57 UTC
Read the original article
Hit count: 173
c#
|algorithms
There is an O(n) solution to the problem of determining if an integer is a palindrome below. Is it possible to solve this problem in O(log n) or better?
static void IsPalindrome(int Number)
{
int OrignalNum = Number;
int Reverse = 0;
int Remainder = 0;
if (Number > 0)
{
while (Number > 0)
{
Remainder = Number % 10;
Reverse = Reverse * 10 + Remainder;
Number = Number / 10;
}
if (OrignalNum == Reverse)
Console.WriteLine("It is a Palindrome");
else
Console.WriteLine("It is not a Palindrome");
}
else
Console.WriteLine("Enter Number Again");
}
© Programmers or respective owner